package com.dropdb.demo.controller.admin;

import com.dropdb.demo.bean.bo.AdminLogListBO;
import com.dropdb.demo.bean.vo.BaseRespVO;
import com.dropdb.demo.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("admin/log")
public class AdminLogController {

    @Autowired
    LogService logService;

    @GetMapping("list")
    public BaseRespVO list(@Valid AdminLogListBO adminLogListBo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return BaseRespVO.error(502, bindingResult.getFieldError().getDefaultMessage());
        }
        return BaseRespVO.ok(logService.list(adminLogListBo));
    }
}
